<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="考生编号" prop="candidateId">
        <el-input
          v-model="queryParams.candidateId"
          placeholder="请输入考生编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准考证号" prop="examNumber">
        <el-input
          v-model="queryParams.examNumber"
          placeholder="请输入准考证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:db_qualification:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:db_qualification:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          @click="clickIdCard"
        >识别</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-coordinate"
          size="mini"
          @click="handleGenerateDbIdentityList"
          v-hasPermi="['system:db_qualification:generate']"
        >生成递补身份验证名单</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="db_qualificationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="" align="center" prop="id" />-->
      <el-table-column label="考生编号" align="center" prop="candidateId" width="120"/>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="身份证号" align="center" prop="idCard"  width="200"/>
      <el-table-column label="准考证号" align="center" prop="examNumber"  width="120"/>
      <el-table-column label="行测成绩" align="center" prop="administrativeAptitudeScore" />
      <el-table-column label="申论成绩" align="center" prop="essayScore" />
      <el-table-column label="专业科目成绩" align="center" prop="professionalSubjectScore"  width="120"/>
      <el-table-column label="总成绩" align="center" prop="totalScore" />
      <el-table-column label="专业技能测试成绩" align="center" prop="professionalSkillTestScore"  width="130"/>
      <el-table-column label="报考单位" align="center" prop="appliedUnit"  width="180"/>
      <el-table-column label="报考职位" align="center" prop="appliedPosition"  width="180"/>
      <el-table-column label="招考人数" align="center" prop="recruitmentNumber" />
      <el-table-column label="面试比例" align="center" prop="interviewRatio" />
      <el-table-column label="排名" align="center" prop="ranking" />
      <el-table-column label="毕业院校" align="center" prop="graduationSchool"  width="180"/>
      <el-table-column label="是否增加专业技能测试" align="center" prop="hasProfessionalSkillTest"  width="180"/>
      <el-table-column label="职位类别" align="center" prop="positionCategory" />
      <el-table-column label="资格审查结果" align="center" prop="qualificationReviewResult" width="120">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.qualificationReviewResult != null" :type="scope.row.qualificationReviewResult == '未通过' ? 'danger' : 'success'">{{scope.row.qualificationReviewResult}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="modifyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:db_qualification:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:db_qualification:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改四级联考递补资格审查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="考生编号" prop="candidateId">
              <el-input v-model="form.candidateId" placeholder="请输入考生编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-input v-model="form.gender" placeholder="请输入性别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="form.idCard" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="准考证号" prop="examNumber">
              <el-input v-model="form.examNumber" placeholder="请输入准考证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报考单位" prop="appliedUnit">
              <el-input v-model="form.appliedUnit" placeholder="请输入报考单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报考职位" prop="appliedPosition">
              <el-input v-model="form.appliedPosition" placeholder="请输入报考职位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业院校" prop="graduationSchool">
              <el-input v-model="form.graduationSchool" placeholder="请输入毕业院校" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="增加专业技能测试" prop="hasProfessionalSkillTest">
              <el-input v-model="form.hasProfessionalSkillTest" placeholder="请输入是否增加专业技能测试" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职位类别" prop="positionCategory">
              <el-input v-model="form.positionCategory" placeholder="请输入职位类别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="编号" prop="registrationId">
              <el-input v-model="form.bianhao" placeholder="请输入编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资格审查结果" prop="qualificationReviewResult">
              <el-radio v-model="form.qualificationReviewResult" label="通过">通过</el-radio>
              <el-radio v-model="form.qualificationReviewResult" label="未通过">未通过</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考生照片" prop="photoPath">
              <div v-if="form.idCard">
                <img :src="photoUrl + form.idCard + '.jpg'" style="vertical-align: bottom; width: 100px; height: 140px;" />
                <!--                                <el-button style="margin-left:20px" type="danger" @click="deletephoto(form.idCard)">删除</el-button>-->
              </div>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-checkbox v-model="upload.updateSupport" />更新已存在数据
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDb_qualification, getDb_qualification, delDb_qualification, addDb_qualification, updateDb_qualification, exportDb_qualification, generateDbIdentityList } from "@/api/system/db_qualification";
import { getToken } from "@/utils/auth";
import axios from 'axios'
import { listIdentity } from '@/api/system/identity'

export default {
  name: "Db_qualification",
  data() {
    return {
      datebirth:"",
      photoUrl: process.env.VUE_APP_BASE_API + "/profile/",
      barcodeUrl: process.env.VUE_APP_BASE_API + "/profile/barcode/",
      printContent:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 四级联考递补资格审查表格数据
      db_qualificationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        candidateId: null,
        name: null,
        idCard: null,
        examNumber: null,
        appliedUnit: null,
        appliedPosition: null,
        hasProfessionalSkillTest: null,
        positionCategory: null,
        qualificationReviewResult: null,
        modifyTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        idCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        examNumber: [
          { required: true, message: "准考证号不能为空", trigger: "blur" }
        ],
        modifyTime: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ]
      },
      // 导入相关参数
      upload: {
        title: "递补资格审查数据导入",
        open: false,
        updateSupport: false,
        isUploading: false,
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/system/db_qualification/importData"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    clickIdCard() {
      axios.get('http://127.0.0.1:19196/readcard')
        .then((res) => {
          let idCard = res.data.certNumber
          console.log(idCard)
          this.queryParams.pageNum = 1;
          this.queryParams.idCard = idCard;
          this.loading = true;
          listDb_qualification(this.queryParams).then(response => {
            this.db_qualificationList = response.rows;
            this.total = response.total;
            this.loading = false;
            // 检查结果数量是否为1，如果是则弹出修改窗口
            if (this.db_qualificationList.length === 1) {
              this.handleUpdate(this.db_qualificationList[0]);
            }else{
              this.$message.error('未查询到此人');
            }
            this.queryParams = {}
            this.getList()
          });
        })
    },
    /** 查询四级联考递补资格审查列表 */
    getList() {
      this.loading = true;
      listDb_qualification(this.queryParams).then(response => {
        this.db_qualificationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        candidateId: null,
        name: null,
        gender: null,
        idCard: null,
        examNumber: null,
        administrativeAptitudeScore: null,
        essayScore: null,
        professionalSubjectScore: null,
        totalScore: null,
        professionalSkillTestScore: null,
        appliedUnit: null,
        appliedPosition: null,
        recruitmentNumber: null,
        interviewRatio: null,
        ranking: null,
        graduationSchool: null,
        hasProfessionalSkillTest: null,
        positionCategory: null,
        isAlternate: null,
        qualificationReviewResult: null,
        identityVerificationResult: null,
        physicalTestResult: null,
        finalResult: null,
        modifyTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加四级联考递补资格审查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDb_qualification(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改四级联考递补资格审查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDb_qualification(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDb_qualification(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除四级联考递补资格审查编号为"' + ids + '"的数据项？').then(function() {
        return delDb_qualification(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/db_qualification/export', {
        ...this.queryParams
      }, `四级联考递补资格审查数据_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "四级联考递补资格审查数据导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/db_qualification/importTemplate', {
      }, `四级联考递补资格审查数据导入模板.xlsx`);
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    /** 生成递补身份验证名单 */
    handleGenerateDbIdentityList() {
      this.$modal.confirm('确认生成递补身份验证名单吗？').then(function() {
        return generateDbIdentityList();
      }).then(response => {
        this.$modal.msgSuccess(response.msg);
      }).catch(() => {});
    }
  }
};
</script>
